package com.qiaoyanqing.textdemoqyq7.Broadcases;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

/**
 * Created by Administrator on 2016/11/17.
 */

public class IntReceiver extends BroadcastReceiver{


    @Override
    public void onReceive(Context context, Intent intent) {
         String action =intent.getAction();
        if(action.equals(ConnectivityManager.CONNECTIVITY_ACTION)){
              ConnectivityManager manager= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo info=(manager==null?manager.getActiveNetworkInfo():null);
            if (info != null) {
                if (info.isConnected()){
                    Toast.makeText(context, "网络无连接", Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(context, "网络断开", Toast.LENGTH_SHORT).show();
                }
            }else {
                Toast.makeText(context, "联网成功", Toast.LENGTH_SHORT).show();
            }
        }

    }
}
